﻿using UnityEngine;
using System.Collections;

public class BattleUIManager : Scene {
	public Animation[] enermyMemberStatusBarAni;
	public Animation[] myMemberStatusBarAni;

	public GameObject[] myMemberHpBarTurnOn1;
	public GameObject myMemberHpBarTurnOff1;
	public GameObject[] myMemberHpBarTurnOn2;
	public GameObject myMemberHpBarTurnOff2;
	public GameObject[] myMemberHpBarTurnOn3;
	public GameObject myMemberHpBarTurnOff3;
	public GameObject[] myMemberHpBarTurnOn4;
	public GameObject myMemberHpBarTurnOff4;
	public GameObject[] enermyMemberHpBarTurnOn1;
	public GameObject enermyMemberHpBarTurnOff1;
	public GameObject[] enermyMemberHpBarTurnOn2;
	public GameObject enermyMemberHpBarTurnOff2;
	public GameObject[] enermyMemberHpBarTurnOn3;
	public GameObject enermyMemberHpBarTurnOff3;
	public GameObject[] enermyMemberHpBarTurnOn4;
	public GameObject enermyMemberHpBarTurnOff4;

	public UISprite[] myMemberCharImgTurnPlayer1;
	public UISprite[] EnermyMemberCharImgTurnPlayer1;
	public UISprite[] myMemberCharImgTurnPlayer2;
	public UISprite[] EnermyMemberCharImgTurnPlayer2;
	public UISprite[] myMemberCharImgTurnPlayer3;
	public UISprite[] EnermyMemberCharImgTurnPlayer3;
	public UISprite[] myMemberCharImgTurnPlayer4;
	public UISprite[] EnermyMemberCharImgTurnPlayer4;
	public UISprite[] myMemberCharImgCoAttackPlayer1;
	public UISprite[] EnermyMemberCharImgCoAttackPlayer1;
	public UISprite[] myMemberCharImgCoAttackPlayer2;
	public UISprite[] EnermyMemberCharImgCoAttackPlayer2;
	public UISprite[] myMemberCharImgCoAttackPlayer3;
	public UISprite[] EnermyMemberCharImgCoAttackPlayer3;
	public UISprite[] myMemberCharImgCoAttackPlayer4;
	public UISprite[] EnermyMemberCharImgCoAttackPlayer4;

	public GameObject bossHpBarObject;
	public GameObject noBossHpBarObject;

	public UISprite bossCharImage;
	public UILabel bossNameLabel;
	public UILabel bossTotalDamageLabel;
	public UILabel bossCurrentHPLabel;
	public GameObject bossHpBar;

	public Animation coAttackLabelAni;

	public GameObject waveTextObject;
	public GameObject skillTextObject;
	public UILabel skillTextLabel;
	public GameObject defenseTextObject;
	public UISprite defenseTextPortrait;
	public UILabel defenseTextCounter;
	public UILabel currendWaveIndexLabel;
	public UILabel maxWaveIndexLabel;
	 
	public Animation startBattleAnimation;
	public UILabel[] startBattleAnimationPlayerInfoLabel;
	public Animation waveBattleAnimation;
	public UISprite waveIndexImage;
	public GameObject secondWaveObject;
	public GameObject finalWaveObject;

	public MagicWaveGage superGage;
	public GameObject[] superGageObjects;
	public GameObject overDriveTextBySuperGage;
	public GameObject superGageOverDriveOnObject;

	public GameObject[] supportAttackTextEffect;

	public GameObject friendAttackButtonObject;
	public GameObject speedUpButtonObject;

	public GameObject battleUIObject;

	public Animation[] superGageAnimations;

	public GameObject overDriveStartTextObject;
	public GameObject overDriveTimerObject;
	public UILabel overDriveTimerNumberLabel;
	public UILabel overDriveTimerDecimalNumberLabel;

	public GameObject comboEffectObject;
	public UILabel comboCountLabel;

	public GameObject battleWinTextEffect;
	public GameObject battleLoseTextEffect;

	public GameObject superSkillCrystalRootObject;
	public GameObject[] superSkillCrystalObject;
	public GameObject crystalBrokenEffect;

	private static BattleUIManager instance;
	
	public static BattleUIManager Instance{
		get{
			return instance;
		}
	}

	public override void AwakeObject ()
	{
		base.AwakeObject ();

		instance = this;

		playerDamageHUDText = new HUDText[4];
		enermyDamageHUDText = new HUDText[4];
		enemySkillDamageHUDText = new HUDText[4];
		playerHealHUDText = new HUDText[4];
	}

	public override void StartObject ()
	{
		base.StartObject ();

		Debug.Log(overDriveTime);

		if( BattleManager.Instance.isBossBattle )
		{
			bossNameLabel.text = TextController.GetStringWithId(string.Format("bossName{0}", UserData.Instance.raidBossId));
			bossHpBarObject.SetActive(true);
			noBossHpBarObject.SetActive(false);
		}
		else
		{
//			if(!BattleManager.Instance.bUseMassiveBattleUI) {
//				bossHpBarObject.SetActive(false);
//				noBossHpBarObject.SetActive(true);
//			}
		}
		
		if( UserData.Instance.battleFriendId == 0 )
			friendAttackButtonObject.GetComponent<EPButton>().isEnabled = false;

//		SetPlayerInfos();

		friendAttackButtonObject.GetComponent<EPButton>().isEnabled = false;
	}

	float overDriveTime = 0;
	public override void UpdateScene ()
	{
		base.UpdateScene ();

		if( BattleManager.Instance.isOverdriveReady )
		{
			overDriveTime = overDriveTime - (Time.deltaTime/BattleSetting.Instance.overdriveModeTimeScale);
//			Debug.LogError(overDriveTime);
//			Debug.LogError((Time.deltaTime/BattleSetting.Instance.overdriveModeTimeScale));
			string[] timeString = overDriveTime.ToString().Split('.');
			overDriveTimerNumberLabel.text = timeString[0];
			overDriveTimerDecimalNumberLabel.text = string.Format(".{0}", timeString[1]);
		}
	}

	bool isHoldSppedButon = false;
	public override void UpdateTouch ()
	{
		base.UpdateTouch ();

		if( Input.GetMouseButton(0) && isClickedSpeedButton)
		{
			Time.timeScale = 4;
		}
		if( Input.GetMouseButtonUp(0) && isClickedSpeedButton)
		{
			isClickedSpeedButton = false;
            //speedUpButtonObject.GetComponent<Animation>().Stop();
            //speedUpButtonObject.SetActive(false);
			Time.timeScale = 1;
		}
	}

	public void ShowStarBattleAnimation()
	{
		if( BattleManager.Instance.isPvp )
		{
			startBattleAnimationPlayerInfoLabel[0].text = UserData.Instance.userModel.name;
			if( UserData.Instance.quickPVPUserModel != null )
				startBattleAnimationPlayerInfoLabel[1].text = UserData.Instance.quickPVPUserModel.name;
			else
				startBattleAnimationPlayerInfoLabel[1].text = "";
			startBattleAnimation.gameObject.SetActive(true);
			startBattleAnimation.Play("Battle_Start_PVP");
		}
		else if( BattleManager.Instance.isBossBattle )
		{
			startBattleAnimationPlayerInfoLabel[1].text = TextController.GetStringWithId(string.Format("bossName{0}", UserData.Instance.raidBossId));
			startBattleAnimation.gameObject.SetActive(true);
			startBattleAnimation.Play("Battle_Start_Boss");
		}
		else
		{
			startBattleAnimation.gameObject.SetActive(true);
			startBattleAnimation.Play("Battle_Start_PVE");
		}

		SoundController.PlaySound("UI_popup_start");

		Invoke("HideStarBattleAnimation", 3f);
	}

	public void HideStarBattleAnimation()
	{
		startBattleAnimation.gameObject.SetActive(false);
	}

	public void SetPlayerInfos()
	{
		if( BattleManager.Instance.isBossBattle )
		{
			foreach(UISprite sprite in myMemberCharImgTurnPlayer1)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[0].myModelName);
			foreach(UISprite sprite in myMemberCharImgTurnPlayer2)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[1].myModelName);
			foreach(UISprite sprite in myMemberCharImgTurnPlayer3)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[2].myModelName);
			foreach(UISprite sprite in myMemberCharImgTurnPlayer4)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[3].myModelName);
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer1)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[0].myModelName);
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer2)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[1].myModelName);
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer3)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[2].myModelName);
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer4)
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[3].myModelName);

            PortraitControl.SetBattlePortrait(bossCharImage, BattleManager.Instance.enemyList[0].myModelName);
		}
		else
		{
            foreach(UISprite sprite in myMemberCharImgTurnPlayer1)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[0].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgTurnPlayer2)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[1].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgTurnPlayer3)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[2].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgTurnPlayer4)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[3].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer1)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[0].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer2)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[1].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer3)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[2].myModelName);
            }
			foreach(UISprite sprite in myMemberCharImgCoAttackPlayer4)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.playerList[3].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgTurnPlayer1)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[0].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgTurnPlayer2)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[1].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgTurnPlayer3)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[2].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgTurnPlayer4)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[3].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgCoAttackPlayer1)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[0].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgCoAttackPlayer2)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[1].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgCoAttackPlayer3)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[2].myModelName);
            }
			foreach(UISprite sprite in EnermyMemberCharImgCoAttackPlayer4)
            {
                PortraitControl.SetBattlePortrait(sprite, BattleManager.Instance.enemyList[3].myModelName);
            }
		}
//		GameData.Inst.ModelDefineDic[pair.Value.model]
	}

	public void ResetEnermyHpBar()
	{
		if(BattleManager.Instance.bUseMassiveBattleUI)
			return;
		if( BattleManager.Instance.isBossBattle && UserData.Instance.raidBossStartData!=null)
		{
			DBossData bossData = GameData.Inst.GetBossData_Old(UserData.Instance.raidBossId);
			int bossMaxHP = bossData.HP+(bossData.hpMod*UserData.Instance.raidBossStartData.lv);
			Vector3 mDOffPos1 = bossHpBar.transform.localPosition;
			float afterDamagePercentOff = 1500-((UserData.Instance.raidBossStartData.hp/(float)bossMaxHP)*1500);
			mDOffPos1.x = -afterDamagePercentOff;
			bossHpBar.transform.localPosition = mDOffPos1;

			bossCurrentHPLabel.text = UserData.Instance.raidBossStartData.hp.ToString();
		}
		else
		{
			Vector3 pos = enermyMemberHpBarTurnOn1[0].transform.localPosition;
			pos.x = -106;
			enermyMemberHpBarTurnOn1[0].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn1[1].transform.localPosition;
			pos.x = -116;
			enermyMemberHpBarTurnOn1[1].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn2[0].transform.localPosition;
			pos.x = -106;
			enermyMemberHpBarTurnOn2[0].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn2[1].transform.localPosition;
			pos.x = -116;
			enermyMemberHpBarTurnOn2[1].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn3[0].transform.localPosition;
			pos.x = -106;
			enermyMemberHpBarTurnOn3[0].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn3[1].transform.localPosition;
			pos.x = -116;
			enermyMemberHpBarTurnOn3[1].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn4[0].transform.localPosition;
			pos.x = -106;
			enermyMemberHpBarTurnOn4[0].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOn4[1].transform.localPosition;
			pos.x = -116;
			enermyMemberHpBarTurnOn4[1].transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOff1.transform.localPosition;
			pos.x = -166;
			enermyMemberHpBarTurnOff1.transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOff2.transform.localPosition;
			pos.x = -166;
			enermyMemberHpBarTurnOff2.transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOff3.transform.localPosition;
			pos.x = -166;
			enermyMemberHpBarTurnOff3.transform.localPosition = pos;
			pos = enermyMemberHpBarTurnOff4.transform.localPosition;
			pos.x = -166;
			enermyMemberHpBarTurnOff4.transform.localPosition = pos;
		}
	}

	public void UpdateMemberHpBarNoEffect(bool isEnermy, int index, int damage, int totalDamage, int currentHp, int maxHp)
	{
		if(BattleManager.Instance.bUseMassiveBattleUI)
			return;
		if(index>4)
			return;
		Debug.LogWarning("UpdateMemberHpBarNoEffect - " + isEnermy + " --- " + index); 
		if( !isEnermy )
		{
			if( index-1 == 0 )
			{
				//				ShowStatusBarTurnOnEffect(isEnermy, index);
				Vector3 mHPos1 = myMemberHpBarTurnOn1[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn1[0].transform.localPosition = mHPos1;
				mHPos1.x += 10f;
				myMemberHpBarTurnOn1[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = myMemberHpBarTurnOff1.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff1.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 1 )
			{
				Vector3 mHPos1 = myMemberHpBarTurnOn2[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn2[0].transform.localPosition = mHPos1;
				mHPos1.x += 10f;
				myMemberHpBarTurnOn2[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = myMemberHpBarTurnOff2.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff2.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 2 )
			{
				Vector3 mHPos1 = myMemberHpBarTurnOn3[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn3[0].transform.localPosition = mHPos1;
				mHPos1.x += 10f;
				myMemberHpBarTurnOn3[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = myMemberHpBarTurnOff3.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff3.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 3 )
			{
				Vector3 mHPos1 = myMemberHpBarTurnOn4[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn4[0].transform.localPosition = mHPos1;
				mHPos1.x += 10f;
				myMemberHpBarTurnOn4[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = myMemberHpBarTurnOff4.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff4.transform.localPosition = mDOffPos1;
			}
		}
		else
		{
			if( index-1 == 0 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn1[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn1[0].transform.localPosition = mHPos1;
				mHPos1.x -= 10f;
				enermyMemberHpBarTurnOn1[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff1.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff1.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 1 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn2[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn2[0].transform.localPosition = mHPos1;
				mHPos1.x -= 10f;
				enermyMemberHpBarTurnOn2[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff2.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff2.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 2 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn3[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn3[0].transform.localPosition = mHPos1;
				mHPos1.x -= 10f;
				enermyMemberHpBarTurnOn3[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff3.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff3.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 3 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn4[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn4[0].transform.localPosition = mHPos1;
				mHPos1.x -= 10f;
				enermyMemberHpBarTurnOn4[1].transform.localPosition = mHPos1;
				
				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff4.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff4.transform.localPosition = mDOffPos1;
			}
		}
	}

	int totalBossDamage = 0;
	public void UpdateMemberHpBarEffect(bool isEnermy, bool isBoss, int index, int damage, int totalDamage, int currentHp, int maxHp, int hitCount)
	{
		if(BattleManager.Instance.bUseMassiveBattleUI)
			return;
		if(index>4)
			return;
		Debug.LogWarning("UpdateMemberHpBarEffect - " + isEnermy + " --- " + index); 
		if( isBoss )
		{			
			Vector3 mDOffPos1 = bossHpBar.transform.localPosition;
			float afterDamagePercentOff = 1500-((currentHp/(float)maxHp)*1500);
			mDOffPos1.x = -afterDamagePercentOff;
			bossHpBar.transform.localPosition = mDOffPos1;

			bossCurrentHPLabel.text = currentHp.ToString();

			totalBossDamage += totalDamage;
			bossTotalDamageLabel.text = totalBossDamage.ToString();

			return;
		}
		if( !isEnermy )
		{
			if( index-1 == 0 )
			{
//				ShowStatusBarTurnOnEffect(isEnermy, index);
				Vector3 mHPos1 = myMemberHpBarTurnOn1[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn1[0].transform.localPosition = mHPos1;
				if( hitCount == 1 && maxHp != currentHp )
				{
					Vector3 mDPos1 = myMemberHpBarTurnOn1[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp+damage)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = 116+afterDamagePercent;
					myMemberHpBarTurnOn1[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x += 10f;
				TweenPosition twPos = TweenPosition.Begin(myMemberHpBarTurnOn1[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = myMemberHpBarTurnOff1.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff1.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 1 )
			{
				Vector3 mHPos1 = myMemberHpBarTurnOn2[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn2[0].transform.localPosition = mHPos1;
				if( hitCount == 1 && maxHp != currentHp  )
				{
					Vector3 mDPos1 = myMemberHpBarTurnOn2[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp+damage)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = 116+afterDamagePercent;
					myMemberHpBarTurnOn2[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x += 10f;
				TweenPosition twPos = TweenPosition.Begin(myMemberHpBarTurnOn2[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = myMemberHpBarTurnOff2.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff2.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 2 )
			{
				Vector3 mHPos1 = myMemberHpBarTurnOn3[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn3[0].transform.localPosition = mHPos1;
				if( hitCount == 1 && maxHp != currentHp )
				{
					Vector3 mDPos1 = myMemberHpBarTurnOn3[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp+damage)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = 116+afterDamagePercent;
					myMemberHpBarTurnOn3[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x += 10f;
				TweenPosition twPos = TweenPosition.Begin(myMemberHpBarTurnOn3[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = myMemberHpBarTurnOff3.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff3.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 3 )
			{
				Vector3 mHPos1 = myMemberHpBarTurnOn4[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = 106+afterHpPercent;
				myMemberHpBarTurnOn4[0].transform.localPosition = mHPos1;
				if( hitCount == 1 && maxHp != currentHp )
				{
					Vector3 mDPos1 = myMemberHpBarTurnOn4[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp+damage)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = 116+afterDamagePercent;
					myMemberHpBarTurnOn4[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x += 10f;
				TweenPosition twPos = TweenPosition.Begin(myMemberHpBarTurnOn4[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = myMemberHpBarTurnOff4.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = 166+afterDamagePercentOff;
				myMemberHpBarTurnOff4.transform.localPosition = mDOffPos1;
			}
		}
		else
		{
			if( index-1 == 0 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn1[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn1[0].transform.localPosition = mHPos1;
				if( hitCount == 1 )
				{
					Vector3 mDPos1 = enermyMemberHpBarTurnOn1[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp+damage)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = -116-afterDamagePercent;
					enermyMemberHpBarTurnOn1[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x -= 10f;
				TweenPosition twPos = TweenPosition.Begin(enermyMemberHpBarTurnOn1[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff1.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff1.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 1 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn2[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn2[0].transform.localPosition = mHPos1;
				if( hitCount == 1 )
				{
					Vector3 mDPos1 = enermyMemberHpBarTurnOn2[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp+damage)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = -116-afterDamagePercent;
					enermyMemberHpBarTurnOn2[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x -= 10f;
				TweenPosition twPos = TweenPosition.Begin(enermyMemberHpBarTurnOn2[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff2.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff2.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 2 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn3[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn3[0].transform.localPosition = mHPos1;
				if( hitCount == 1 )
				{
					Vector3 mDPos1 = enermyMemberHpBarTurnOn3[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = -116-afterDamagePercent;
					enermyMemberHpBarTurnOn3[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x -= 10f;
				TweenPosition twPos = TweenPosition.Begin(enermyMemberHpBarTurnOn3[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff3.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff3.transform.localPosition = mDOffPos1;
			}
			else if( index-1 == 3 )
			{
				Vector3 mHPos1 = enermyMemberHpBarTurnOn4[0].transform.localPosition;
				float afterHpPercent = 212-((currentHp/(float)maxHp)*212);
				Debug.Log("afterHpPercent - " + afterHpPercent);
				mHPos1.x = -106-afterHpPercent;
				enermyMemberHpBarTurnOn4[0].transform.localPosition = mHPos1;
				if( hitCount == 1 )
				{
					Vector3 mDPos1 = enermyMemberHpBarTurnOn4[1].transform.localPosition;
					float afterDamagePercent = 212-(((currentHp)/(float)maxHp)*212);
					Debug.Log("afterDamagePercent - " + afterDamagePercent);
					mDPos1.x = -116-afterDamagePercent;
					enermyMemberHpBarTurnOn4[1].transform.localPosition = mDPos1;
				}

				Vector3 pos = mHPos1;
				pos.x -= 10f;
				TweenPosition twPos = TweenPosition.Begin(enermyMemberHpBarTurnOn4[1], 0.5f, pos);
				twPos.delay = 1f;
				twPos.ignoreTimeScale = true;

				Vector3 mDOffPos1 = enermyMemberHpBarTurnOff4.transform.localPosition;
				float afterDamagePercentOff = 305-((currentHp/(float)maxHp)*305);
				mDOffPos1.x = -166-afterDamagePercentOff;
				enermyMemberHpBarTurnOff4.transform.localPosition = mDOffPos1;
			}
		}

		ShowStatusBarDamageEffect(!isEnermy, index);
		ShowDamageHUDText(!isEnermy, index, damage, false);
	}

	public void ShowStatusBarTurnOnEffect(bool isMe, int index)
	{
		if(BattleManager.Instance.bUseMassiveBattleUI)
			return;
		if(index>4)
			return;
		if( isMe )
		{
			myMemberStatusBarAni[index-1].Play("battle_char panel_turn on");
		}
		else
		{
			enermyMemberStatusBarAni[index-1].Play("battle_char panel_turn on");
		}
	}

	public void ShowStatusBarTurnOffEffect(bool isMe, int index)
	{
		if(BattleManager.Instance.bUseMassiveBattleUI)
			return;
		if(index>4)
			return;
		Debug.Log("ShowStatusBarTurnOffEffect  "+index);
		if( isMe )
		{
			myMemberStatusBarAni[index-1].Play("battle_char panel_turn off");
		}
		else
		{
			enermyMemberStatusBarAni[index-1].Play("battle_char panel_turn off");
		}
	}

	public void ShowStatusBarDamageEffect(bool isMe, int index)
	{
		if(index>4)
			return;
		if( isMe )
		{
			myMemberStatusBarAni[index-1].Play("battle_char panel_damage");
		}
		else
		{
			enermyMemberStatusBarAni[index-1].Play("battle_char panel_damage");
		}
	}


	public HUDText[] playerDamageHUDText;
	public HUDText[] enermyDamageHUDText;
	public HUDText[] enemySkillDamageHUDText;
	public HUDText[] playerHealHUDText;

	HUDText CreateHudText(int nType)
	{
		if(nType==1) {//playerDamageHUDText
			if(DamageFont.effectFontRes_damage_player==null)
				DamageFont.effectFontRes_damage_player = BattleManager.Instance.massUITrans.FindChild("LabelPlayerDamage").gameObject;
			GameObject child = NGUITools.AddChild(BattleManager.Instance.massUITrans.gameObject, DamageFont.effectFontRes_damage_player);
			child.SetActive(true);
			return child.GetComponent<HUDText>();
		}
		else if(nType==2) {//enermyDamageHUDText
			if(DamageFont.effectFontRes_damage_normal_enemy==null)
				DamageFont.effectFontRes_damage_normal_enemy = BattleManager.Instance.massUITrans.FindChild("LabelEnemyDamage").gameObject;
			GameObject child = NGUITools.AddChild(BattleManager.Instance.massUITrans.gameObject, DamageFont.effectFontRes_damage_normal_enemy);
			child.SetActive(true);
			return child.GetComponent<HUDText>();
		}
		else if(nType==3) {//enemySkillDamageHUDText
			if(DamageFont.effectFontRes_damage_skill_enemy==null)
				DamageFont.effectFontRes_damage_skill_enemy = BattleManager.Instance.massUITrans.FindChild("LabelEnemySkillDamage").gameObject;
			GameObject child = NGUITools.AddChild(BattleManager.Instance.massUITrans.gameObject, DamageFont.effectFontRes_damage_skill_enemy);
			child.SetActive(true);
			return child.GetComponent<HUDText>();
		}
		else if(nType==4) {//playerHealHUDText
			if(DamageFont.effectFontRes_heal==null)
				DamageFont.effectFontRes_heal = BattleManager.Instance.massUITrans.FindChild("LabelHeal").gameObject;
			GameObject child = NGUITools.AddChild(BattleManager.Instance.massUITrans.gameObject, DamageFont.effectFontRes_heal);
			child.SetActive(true);
			return child.GetComponent<HUDText>();
		}
		return null;
	}

	public void ShowDamageHUDText(bool isPlayer, int index, int damage, bool isAttackedBySkill)
	{
		if(index>4)
			return;

		if( isPlayer )
		{
			if(playerDamageHUDText[index-1]==null)
				playerDamageHUDText[index-1] = CreateHudText(1);
			UIFollowTarget ftarget = playerDamageHUDText[index-1].GetComponent<UIFollowTarget>();
			if( ftarget == null )
				ftarget = playerDamageHUDText[index-1].gameObject.AddComponent<UIFollowTarget>();
			ftarget.target = BattleManager.Instance.playerList[index-1].pawnManifest.hudHeadTrans;
			if(ftarget.target !=null && ftarget.IsTargetVisible())
				playerDamageHUDText[index-1].Add(damage.ToString(), Color.white, 0f, 2);
		}
		else
		{
			if(isAttackedBySkill) {
				if(enemySkillDamageHUDText[index-1]==null)
					enemySkillDamageHUDText[index-1] = CreateHudText(3);
				UIFollowTarget ftarget = enemySkillDamageHUDText[index-1].GetComponent<UIFollowTarget>();
				if( ftarget == null ) 
					ftarget = enemySkillDamageHUDText[index-1].gameObject.AddComponent<UIFollowTarget>();
				ftarget.target = BattleManager.Instance.enemyList[index-1].pawnManifest.hudHeadTrans;
				if(ftarget.target !=null && ftarget.IsTargetVisible())
					enemySkillDamageHUDText[index-1].Add(damage.ToString(), Color.white, 0f, 2);
			}
			else {
				if(enermyDamageHUDText[index-1]==null)
					enermyDamageHUDText[index-1] = CreateHudText(2);
				UIFollowTarget ftarget = enermyDamageHUDText[index-1].GetComponent<UIFollowTarget>();
				if( ftarget == null ) 
					ftarget = enermyDamageHUDText[index-1].gameObject.AddComponent<UIFollowTarget>();
				ftarget.target = BattleManager.Instance.enemyList[index-1].pawnManifest.hudHeadTrans;
				if(ftarget.target !=null && ftarget.IsTargetVisible())
					enermyDamageHUDText[index-1].Add(damage.ToString(), Color.white, 0f, 2);
			}
		}
	}

	public void ShowhealHUDText(bool isPlayer, int index, int heal)
	{
		if(index>4)
			return;
		if(playerHealHUDText[index-1]==null)
			playerHealHUDText[index-1] = CreateHudText(4);
		UIFollowTarget ftarget = playerHealHUDText[index-1].GetComponent<UIFollowTarget>();
		if( ftarget == null )
			ftarget = playerHealHUDText[index-1].gameObject.AddComponent<UIFollowTarget>();
		if( isPlayer )
		{
			ftarget.target = BattleManager.Instance.playerList[index-1].pawnManifest.hudHeadTrans;
		}
		else
		{
			ftarget.target = BattleManager.Instance.enemyList[index-1].pawnManifest.hudHeadTrans;
		}			
		if(ftarget.target !=null && ftarget.IsTargetVisible())	
			playerHealHUDText[index-1].Add(string.Format("+{0}" ,heal.ToString()), Color.white, 0f, 2);
	}

	public void ClearDamageHUDText(bool isPlayer, int index)
	{
		if(index>4)
			return;
		if( isPlayer )
		{
			if(playerDamageHUDText[index-1]!=null)
				Destroy( playerDamageHUDText[index-1].gameObject.GetComponent<UIFollowTarget>() );
		}
		else
		{
			if(enermyDamageHUDText[index-1]!=null)
				Destroy( enermyDamageHUDText[index-1].gameObject.GetComponent<UIFollowTarget>() );
		}
	}

	public void ShowCoAttackBarEffect(bool isMe, int index, int attackCount)
	{
		if(index>4)
			return;
		StartCoroutine(Co_ShowCoAttackBarEffect(isMe, index, attackCount));
	}

	IEnumerator Co_ShowCoAttackBarEffect(bool isMe, int index, int attackCount)
	{
		Debug.Log("Co_ShowCoAttackBarEffect");
		if( isMe )
		{
			if( attackCount == 1 )
			{
				myMemberStatusBarAni[index-1].Play("battle_char panel_dual on");
				SoundController.PlaySound("UI_support_attack_dual");
			}
			if( attackCount == 2 )
			{
//				yield return new WaitForSeconds(0.3f);
				myMemberStatusBarAni[index-1].Play("battle_char panel_triple on");
				SoundController.PlaySound("UI_support_attack_triple");
			}
			if( attackCount == 3 )
			{
//				yield return new WaitForSeconds(0.3f);
				myMemberStatusBarAni[index-1].Play("battle_char panel_burst on");
				SoundController.PlaySound("UI_support_attack_burst");
			}
		}
		else
		{
			if( attackCount == 1 )
			{
				enermyMemberStatusBarAni[index-1].Play("battle_char panel_dual on");
				SoundController.PlaySound("UI_support_attack_dual");
			}
			if( attackCount == 2 )
			{
//				yield return new WaitForSeconds(0.3f);
				enermyMemberStatusBarAni[index-1].Play("battle_char panel_triple on");
				SoundController.PlaySound("UI_support_attack_triple");
			}
			if( attackCount == 3 )
			{
//				yield return new WaitForSeconds(0.3f);
				enermyMemberStatusBarAni[index-1].Play("battle_char panel_burst on");
				SoundController.PlaySound("UI_support_attack_burst");
			}
		}

		yield return new WaitForSeconds(1f);

		if( isMe )
		{
			if( attackCount == 1 )
			{
				myMemberStatusBarAni[index-1].Play("battle_char panel_dual off");
			}
			if( attackCount == 2 )
			{
//				yield return new WaitForSeconds(0.3f);
				myMemberStatusBarAni[index-1].Play("battle_char panel_triple off");
			}
			if( attackCount == 3 )
			{
//				yield return new WaitForSeconds(0.3f);
				myMemberStatusBarAni[index-1].Play("battle_char panel_burst off");
			}
		}
		else
		{
			if( attackCount == 1 )
			{
				enermyMemberStatusBarAni[index-1].Play("battle_char panel_dual off");
			}
			if( attackCount == 2 )
			{
//				yield return new WaitForSeconds(0.3f);
				enermyMemberStatusBarAni[index-1].Play("battle_char panel_triple off");
			}
			if( attackCount == 3 )
			{
//				yield return new WaitForSeconds(0.3f);
				enermyMemberStatusBarAni[index-1].Play("battle_char panel_burst off");
			}
		}
	}

	public void ShowCoDefenseBarEffect(bool isMe, int index)
	{
		if(index>4)
			return;
		StartCoroutine(Co_ShowCoDefenseBarEffect(isMe, index));
	}
	
	IEnumerator Co_ShowCoDefenseBarEffect(bool isMe, int index)
	{
		Debug.Log("Co_ShowCoDefenseBarEffect");
		if( isMe )
		{
			myMemberStatusBarAni[index-1].Play("battle_char panel_guard on");
		}
		else
		{
			enermyMemberStatusBarAni[index-1].Play("battle_char panel_guard on");
		}
		
		yield return new WaitForSeconds(1f);
		
		if( isMe )
		{
			myMemberStatusBarAni[index-1].Play("battle_char panel_guard off");
		}
		else
		{
			enermyMemberStatusBarAni[index-1].Play("battle_char panel_guard off");
		}
	}

	public void ShowCoAttackText()
	{
		//Debug.LogError("ShowCoAttackText");
//		coAttackLabelAni.gameObject.SetActive(true);
		coAttackLabelAni.Play("battle_attack Text on");
//		ShowSupportAttackTextEffect(index);
	}

	public void HideCoAttackText()
	{
		//Debug.LogError("HideCoAttackText");
		coAttackLabelAni.Play("battle_attack Text off");
//		coAttackLabelAni.gameObject.SetActive(false);
	}

	public void ShowSkillNameText(SkillInfo info)
	{
		skillTextObject.SetActive(true);
		if( !info.isRage )
			skillTextLabel.text = TextController.GetStringWithId(string.Format("SkillNametrait{0}", info.skill.traitID));
		else
			skillTextLabel.text = TextController.GetStringWithId(string.Format("PSkillNametrait{0}", info.skill.traitID));

		Debug.Log(TextController.GetStringWithId(string.Format("SkillNametrait{0}", info.skill.traitID)));
		Debug.Log(skillTextLabel.text);
		skillTextObject.GetComponent<Animation>().Play("battle_attack Text on");

		Invoke("HideSkillNameText", 2f);
	}
	
	public void HideSkillNameText()
	{
		skillTextObject.GetComponent<Animation>().Play("battle_attack Text off");
	}

	public void ShowCoDefenseText(ECharModel charModel, string modelName, int _counter)
	{
		defenseTextObject.SetActive(true);
		//defenseTextPortrait.atlas
		//defenseTextPortrait.spriteName = modelName;
		PortraitControl.SetPortrait(defenseTextPortrait, modelName);
		defenseTextCounter.text = "x"+_counter.ToString();
		//defenseTextObject.GetComponent<Animation>().Play("battle_skill Text on");
		Invoke("HideCoDefenseText", 2f);
	}
	
	public void HideCoDefenseText()
	{
		//defenseTextObject.GetComponent<Animation>().Play("battle_skill Text off");
		defenseTextObject.SetActive(false);
	}

	public void ShowSupportAttackTextEffect(int index)
	{
		StartCoroutine(Co_ShowSupportAttackTextEffect(index-1));
	}

	IEnumerator Co_ShowSupportAttackTextEffect(int index)
	{
		//Debug.LogError("Co_ShowSupportAttackTextEffect - " + index);
//		battle_sup attack_burst on
		supportAttackTextEffect[index].SetActive(true);
		if( index == 0 )
			supportAttackTextEffect[index].GetComponent<Animation>().Play("battle_sup attack_dual on");
		else if( index == 1 )
			supportAttackTextEffect[index].GetComponent<Animation>().Play("battle_sup attack_triple on");
		else if( index == 2 )
			supportAttackTextEffect[index].GetComponent<Animation>().Play("battle_sup attack_burst on");

		yield return new WaitForSeconds(0.5f);

		if( index == 0 )
			supportAttackTextEffect[index].GetComponent<Animation>().Play("battle_sup attack_dual off");
		else if( index == 1 )
			supportAttackTextEffect[index].GetComponent<Animation>().Play("battle_sup attack_triple off");
		else if( index == 2 )
			supportAttackTextEffect[index].GetComponent<Animation>().Play("battle_sup attack_burst off");
//		supportAttackTextEffect[index].SetActive(false);
	}

	public void ReArrangePosBelowBar(int index, bool isOn, bool isMe)
	{
		Debug.Log("isOn : " + isOn);
		for(int i=index+1; i<4; i++)
		{
			if( isOn )
			{
				if( isMe )
				{
					TweenPosition tPos = TweenPosition.Begin(myMemberStatusBarAni[i].gameObject, 0.3f, new Vector3(myMemberStatusBarAni[i].transform.localPosition.x, myMemberStatusBarAni[i].transform.localPosition.y-5f, myMemberStatusBarAni[i].transform.localPosition.z));
					tPos.ignoreTimeScale = true;
				}
				else
				{
					TweenPosition tPos = TweenPosition.Begin(enermyMemberStatusBarAni[i].gameObject, 0.3f, new Vector3(enermyMemberStatusBarAni[i].transform.localPosition.x, enermyMemberStatusBarAni[i].transform.localPosition.y-5f, enermyMemberStatusBarAni[i].transform.localPosition.z));
					tPos.ignoreTimeScale = true;
				}
			}
			else
			{
				if( isMe )
				{
					TweenPosition tPos = TweenPosition.Begin(myMemberStatusBarAni[i].gameObject, 0.3f, new Vector3(myMemberStatusBarAni[i].transform.localPosition.x, myMemberStatusBarAni[i].transform.localPosition.y+5f, myMemberStatusBarAni[i].transform.localPosition.z));
					tPos.ignoreTimeScale = true;
				}
				else
				{
					TweenPosition tPos = TweenPosition.Begin(enermyMemberStatusBarAni[i].gameObject, 0.3f, new Vector3(enermyMemberStatusBarAni[i].transform.localPosition.x, enermyMemberStatusBarAni[i].transform.localPosition.y+5f, enermyMemberStatusBarAni[i].transform.localPosition.z));
					tPos.ignoreTimeScale = true;
				}
			}
		}
	}

	int superGagePhase = 0;
	int crystalPhase = 0;
	public Animation superGageGainAni;
	public void SetSuperGage(int superValue)
	{
		if( superGage == null ) {
			Debug.LogError("superGage null");
			return;
		}
		float ratio = (float)superValue/100.0f;
//		Debug.Log("set super gage  "+ratio);
//		if( ratio >= 1 )
//			ratio = 1.5f;
//		superGage.Amount = ratio;

//		if( superValue == 0 )
//		{
//			foreach(Animation ani in superGageAnimations)
//				ani.gameObject.SetActive(false);
//		}
//		else
//		{
			StartCoroutine(Co_SetSuperGageAnimation(ratio));
//		}
	}
	public void ShowSuperGageFX()
	{
//		if( superGage == null ) {
//			Debug.LogError("superGage null");
//			return;
//		}
//		superGage.ShowFX();
//		superGageGainAni.Play("Ulti_round");
	}

	bool crystalPhase1 = false;
	bool crystalPhase2 = false;
	bool crystalPhase3 = false;
	IEnumerator Co_SetSuperGageAnimation(float ratio)
	{
//		if( superGagePhase == 0 )
//		{
//			superGageAnimations[0].gameObject.SetActive(true);
//			superGageAnimations[0].Play("Ulti_01_in");
//			superGagePhase = 1;
//			yield return new WaitForSeconds(0.3f);
//			superGageAnimations[0].Play("Ulti_01_idle");
//		}
//		if( ratio >= 0.35f && superGagePhase < 2)
//		{
//			superGageAnimations[1].gameObject.SetActive(true);
//			superGageAnimations[1].Play("Ulti_02_in");
//			superGagePhase = 2;
//			yield return new WaitForSeconds(0.3f);
//			superGageAnimations[1].Play("Ulti_02_idle");
//		}
//		if( ratio >= 0.70f && superGagePhase < 3 )
//		{
//			superGageAnimations[2].gameObject.SetActive(true);
//			superGageAnimations[2].Play("Ulti_03_in");
//			superGagePhase = 3;
//			yield return new WaitForSeconds(0.3f);
//			superGageAnimations[2].Play("Ulti_03_idle");
//		}
//		if( ratio >= 1f && superGagePhase < 4)
//		{
//			superGageAnimations[3].gameObject.SetActive(true);
//			superGageAnimations[3].Play("Ulti_04_in");
//			superGagePhase = 4;
//			yield return new WaitForSeconds(0.3f);
//			superGageAnimations[3].Play("Ulti_04_idle");
//		}

		yield return null;

        BattleManager.Instance.massBattleUI.TacticsRatioCur = ratio;

		if( ratio > 0f && ratio < 0.33f )
		{
			superGagePhase = 1;
		}
		else if( ratio >= 0.33f && ratio < 0.66f )
		{
			superGagePhase = 2;
		}
		else if( ratio >= 0.66f && ratio < 1.0f )
		{
			superGagePhase = 3;
		}
		else if( ratio >= 1.0f )
		{
			superGagePhase = 4;
		}

		for(int i=0; i<4; i++)
		{
			if( i < superGagePhase )
				superGageObjects[i].SetActive(true);
			else
				superGageObjects[i].SetActive(false);
		}

		if( !crystalPhase1 && (ratio >= 0f && ratio <0.49f) )
		{
			crystalPhase1 = true;
			crystalPhase2 = false;
			crystalPhase3 = false;
			superSkillCrystalRootObject.GetComponent<Animation>().Play("Crystal_Scale01");
			yield return new WaitForSeconds(1f);
			superSkillCrystalObject[1].SetActive(false);
			superSkillCrystalObject[2].SetActive(false);
			superSkillCrystalObject[0].SetActive(true);
			superSkillCrystalRootObject.GetComponent<Animation>().Play("Crystal_Scale02");
			yield return new WaitForSeconds(1f);
		}
		else if( !crystalPhase2 && (ratio >= 0.50f && ratio <1.0f) )
		{
			crystalPhase1 = false;
			crystalPhase2 = true;
			crystalPhase3 = false;
			superSkillCrystalRootObject.GetComponent<Animation>().Play("Crystal_Scale01");
			yield return new WaitForSeconds(1f);
			superSkillCrystalObject[0].SetActive(false);
			superSkillCrystalObject[2].SetActive(false);
			superSkillCrystalObject[1].SetActive(true);
			superSkillCrystalRootObject.GetComponent<Animation>().Play("Crystal_Scale02");
			yield return new WaitForSeconds(1f);
		}
		else if( !crystalPhase3 && ratio >= 1.0f )
		{
			overDriveTextBySuperGage.SetActive(true);
			overDriveTextBySuperGage.GetComponent<Animation>().Play("Bar_Over Drive ON");
			crystalPhase1 = false;
			crystalPhase2 = false;
			crystalPhase3 = true;
			yield return new WaitForSeconds(0.2f);
			overDriveTextBySuperGage.GetComponent<Animation>().Play("Bar_Over Drive Idle");
			superGageObjects[0].transform.parent.parent.gameObject.GetComponent<Animation>().Play("Ulti gauge");
			superSkillCrystalRootObject.GetComponent<Animation>().Play("Crystal_Scale01");
			yield return new WaitForSeconds(1f);
			superSkillCrystalObject[0].SetActive(false);
			superSkillCrystalObject[1].SetActive(false);
			superSkillCrystalObject[2].SetActive(true);
			superSkillCrystalRootObject.GetComponent<Animation>().Play("Crystal_Scale02");
			yield return new WaitForSeconds(1f);
		}

        if( ratio >= 1.0f )
        {
            BattleManager.Instance.massBattleUI.transform.FindChild("buttons").FindChild("button_Attack").FindChild("off").gameObject.SetActive(false);
            BattleManager.Instance.massBattleUI.transform.FindChild("buttons").FindChild("button_Attack").FindChild("on").gameObject.SetActive(true);
        }
        else
        {
            BattleManager.Instance.massBattleUI.transform.FindChild("buttons").FindChild("button_Attack").FindChild("off").gameObject.SetActive(true);
            BattleManager.Instance.massBattleUI.transform.FindChild("buttons").FindChild("button_Attack").FindChild("on").gameObject.SetActive(false);
        }
	}

	public void SetWaveText(int currentWaveIndex, int MaxWave)
	{
		if( currentWaveIndex == 2 )
			secondWaveObject.SetActive(true);
		else if( currentWaveIndex == 3 ) {
			secondWaveObject.SetActive(false);
			finalWaveObject.SetActive(true);
		}
		waveBattleAnimation.gameObject.SetActive(true);
		waveBattleAnimation.Play();
		SoundController.PlaySound("UI_popup_wave");
		currendWaveIndexLabel.text = currentWaveIndex.ToString();
		maxWaveIndexLabel.text = MaxWave.ToString();
		waveTextObject.SetActive(true);
		Invoke ("HideWaveLabel",1.0f);
	}
	
	void HideWaveLabel()
	{
		waveTextObject.SetActive(false);
	}

	public ExpHUDText[] playerExpHUDText;
	public void ShowBattleResult()
	{
		StartCoroutine("Co_ShowCharExpResult");
	}

	IEnumerator Co_ShowCharExpResult()
	{
        int[][] memberExp = null;
        //for(int i=0; i<4; i++)
        //{	
        //    if( playerExpHUDText[i].GetComponent<UIFollowTarget>() == null )
        //    {
        //        if(BattleManager.Instance.isGameWin)
        //        {
        //            playerExpHUDText[i].gameObject.AddComponent<UIFollowTarget>().target = BattleManager.Instance.playerList[i].pawnManifest.hudHeadTrans;
        //        }
        //        else
        //            playerExpHUDText[i].gameObject.AddComponent<UIFollowTarget>().target = BattleManager.Instance.playerList[i].pawnManifest.transform.FindChild("HUD_Down");
        //    }

            if( WorldSceneManager.isSentSearch && !BattleManager.Instance.isBossBattle )
                memberExp = UserData.Instance.researchResultData.memberExp;
            else if( WorldExtensionBattleStageScene.isExpansionWar )
                memberExp = UserData.Instance.expansionWarResultData.memberExp;
            else if( BattleManager.Instance.isBossBattle )
                memberExp = UserData.Instance.raidBossResultData.memberExp;
            else if( UserData.Instance.isQuickPVPBattle )
                memberExp = UserData.Instance.quickPvPResultData.memberExp;

        //    SoundController.PlaySound("UI_score");
        //    if( memberExp != null )
        //    {
        //        for(int k=0; k<memberExp.Length; k++)
        //        {
        //            if( UserData.Instance.userModel.choiceMembers[i] == memberExp[k][0] )
        //            {
        //                playerExpHUDText[i].SetExpValue(memberExp[k][1]);
        //                continue;
        //            }
        //        }
        //    }
        //}

        Transform trans = BattleManager.Instance.defauntBG.transform.FindChild("Result_Directional light (Real Time)");
        if (trans != null)
        {
			EventlineStaticActor.RealTimeLight.SetActive(false);
            GameObject resultLight = trans.gameObject;
            resultLight.SetActive(true);
        }
		//GameObject probeAnchorPrefab = Resources.Load("Prefab/Battle/LightProbeAnchor_result_pos") as GameObject;
		//GameObject probeAnchor = Instantiate(probeAnchorPrefab) as GameObject;

        GameObject posObj = Resources.Load(string.Format("Prefab/Battle/{0}", SceneController.GetCurrentBattleResultPosName(WorldSceneManager.GetSelectedAreaId()))) as GameObject;
        GameObject resultPos = Instantiate(posObj) as GameObject;
        for(int j=0; j<BattleManager.Instance.playerList.Count; j++)
        {
            Transform tempPosChar = resultPos.transform.FindChild((j + 1).ToString());
			Transform charMainCamTrans = tempPosChar.FindChild("Main Camera");
			BattleManager.Instance.playerList[j].pawnManifest.gameObject.SetActive(true);
			foreach(SkinnedMeshRenderer smRenderer in BattleManager.Instance.playerList[j].pawnManifest.parentPawn.smRenderers)
				smRenderer.lightProbeAnchor = BattleManager.Instance.defauntBG.transform.FindChild("LightProbeAnchor_Result_"+(j+1).ToString());
			Transform cameraPointChar = BattleManager.Instance.playerList[j].pawnManifest.transform.FindChild("Camera_Point");
			BattleManager.Instance.playerList[j].pawnManifest.transform.parent = tempPosChar;
            BattleManager.Instance.playerList[j].pawnManifest.transform.localPosition = Vector3.zero;
            BattleManager.Instance.playerList[j].pawnManifest.transform.localScale = Vector3.one;
            BattleManager.Instance.playerList[j].pawnManifest.GetComponent<Animation>().Play("lobby01");
			if (cameraPointChar != null)
            {
				charMainCamTrans.parent = cameraPointChar.FindChild("Camera_Point01");
				charMainCamTrans.localPosition = Vector3.zero;
				charMainCamTrans.localRotation = Quaternion.identity;
				charMainCamTrans.localScale = Vector3.one;
                //temp.FindChild("Main Camera").position = BattleManager.Instance.playerList[j].pawnManifest.transform.FindChild("Camera_Point").FindChild("Camera_Point01").transform.position;
                //temp.FindChild("Main Camera").rotation = BattleManager.Instance.playerList[j].pawnManifest.transform.FindChild("Camera_Point").FindChild("Camera_Point01").transform.rotation;
				yield return null;
				charMainCamTrans.parent = tempPosChar;
			}
        }

        GameObject obj = Resources.Load("Prefab/Battle/BattleResults_4vs4") as GameObject;
        BattleResultWindow resultWindow = (Instantiate(obj) as GameObject).GetComponent<BattleResultWindow>();
        resultWindow.transform.parent = GameObject.Find("UI Root").transform;
        resultWindow.transform.localScale = Vector3.one;
        resultWindow.transform.localPosition = Vector3.zero;

        obj = Resources.Load("Prefab/Battle/BattleResults_4vs4_Loop") as GameObject;
        GameObject loopEffect = Instantiate(obj) as GameObject;
        loopEffect.transform.parent = GameObject.Find("UI Root").transform;
        loopEffect.transform.localScale = Vector3.one;
        loopEffect.transform.localPosition = Vector3.zero;

        resultWindow.SetCharacterInfos();
        resultPos.GetComponent<Animation>().Play();
        resultWindow.GetComponent<Animation>().Play();
        loopEffect.GetComponent<Animation>().Play();
		
		if( memberExp != null )
		{
            while (!(resultWindow.expDone[0] && resultWindow.expDone[1] && resultWindow.expDone[2] && resultWindow.expDone[3]))
			{
				yield return null;
			}
		}

        ToastManager.Instance.ShowQAToastInHoldList();

        loopEffect.SetActive(false);

		if( BattleManager.Instance.isBossBattle )
		{
			if( BattleManager.Instance.isGameWin && UserData.Instance.raidBossResultData.suppressType == 1 )
			{
				GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_bossresult_popup_01") as GameObject;
				BossBattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BossBattleResultPopup>();
				popup.transform.parent = GameObject.Find("UI Root").transform;
				popup.transform.localScale = Vector3.one;
				popup.transform.localPosition = new Vector3(0f, 130f, 0f);
				popup.legionExp.text = string.Format("+{0}", UserData.Instance.raidBossResultData.legionExp.ToString());
				if( UserData.Instance.raidBossResultData.discoverLegionId == UserData.Instance.userModel.id )
				{
					popup.rewardOffObject[0].SetActive(false);
					popup.rewardOffObject[1].SetActive(false);
					popup.rewardOffObject[2].SetActive(false);
					popup.rewardOnObject[0].SetActive(true);
					popup.rewardOnObject[1].SetActive(true);
					popup.rewardOnObject[2].SetActive(true);
				}
				else
				{
					popup.rewardOffObject[0].SetActive(true);
					popup.rewardOffObject[1].SetActive(false);
					popup.rewardOffObject[2].SetActive(false);
					popup.rewardOnObject[0].SetActive(false);
					popup.rewardOnObject[1].SetActive(true);
					popup.rewardOnObject[2].SetActive(true);
				}

				if( UserData.Instance.battleFriendId == 0 )
				{
					popup.addFriendObject.SetActive(false);
					popup.friendRewardObject.SetActive(false);
				}
				else
				{
					if( UserData.Instance.battleFriendIsMyFriend )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(true);
					}
					else
					{
						popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
						popup.addFriendObject.SetActive(true);
					}
				}
			}
			else
			{
				GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_04") as GameObject;
				BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
				popup.transform.parent = GameObject.Find("UI Root").transform;
				popup.transform.localScale = Vector3.one;
				popup.transform.localPosition = new Vector3(0f, 130f, 0f);
				popup.legionExpLabel.text = string.Format("+{0}", UserData.Instance.raidBossResultData.legionExp.ToString());
                //popup.legionExpLabel2.text = string.Format("+{0}", UserData.Instance.raidBossResultData.legionExp.ToString());
                //popup.winPointLabel.text = string.Format("+{0}", UserData.Instance.raidBossResultData.legionExp.ToString());
				if( UserData.Instance.battleFriendId == 0 )
				{
					popup.addFriendObject.SetActive(false);
					popup.friendRewardObject.SetActive(false);
					popup.GetComponent<Animation>().Play("Battle_Result_Bonus_failed EPNF");
				}
				else
				{
					if( UserData.Instance.battleFriendIsMyFriend )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(true);
					}
					else
					{
						popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
						popup.addFriendObject.SetActive(true);
						popup.friendRewardObject.SetActive(false);
					}
					popup.GetComponent<Animation>().Play("Battle_Result_Bonus_failed EPWF");
				}
			}

			ToastUtility.LevelUpToast();
		}
		else
		{
			ResearchResultModel result = UserData.Instance.researchResultData;
			ExpansionWarResultModel ExpansionResult = UserData.Instance.expansionWarResultData;

			if( WorldExtensionBattleStageScene.isExpansionWar )
			{
				DExtendWar expansionRewardInfo = new DExtendWar();
				if( BattleManager.Instance.isGameWin )
				{
					foreach(DExtendWar info in GameData.Inst.extendWar)
					{
						if( info.regionID == WorldSceneManager.GetSelectedAreaId() )
						{
							if( info.stage == (UserData.Instance.userModel.regions.expansionWarStep == 0?1:(int)UserData.Instance.userModel.regions.expansionWarStep) )
							{
								expansionRewardInfo = info;
								break;
							}
						}
					}

					GameObject bonusPrefab = ResourceLoader.Load("Prefab/UI/battle_result_bonus") as GameObject;
					BattleResultBonus bonus = (Instantiate(bonusPrefab) as GameObject).GetComponent<BattleResultBonus>();
					bonus.transform.parent = GameObject.Find("UI Root").transform;
					bonus.transform.localScale = Vector3.one;
					bonus.transform.localPosition = Vector3.zero;
					DItem bonusItemInfo = new DItem();
					if( expansionRewardInfo.rewardType == 2 )
					{
						foreach(DItem itemInfo in GameData.Inst.item)
						{
							if( itemInfo.itemID == expansionRewardInfo.value )
							{
								if( itemInfo.rarity == 0 )
								{
									bonus.itemGlow.gameObject.SetActive(false);
								}
								bonus.itemImage.spriteName = TextController.GetItemDefine(itemInfo);
								bonus.itemGlow.color = Constants.GetItemGlowRareColorValue(itemInfo.rarity);
								bonus.itemBg.color = Constants.GetItemBGRareColorValue(itemInfo.rarity);
								Color[] decoColor = Constants.GetItemWindowDecoColorValue(itemInfo.rarity);
								bonus.itemWindow_deco1.color = decoColor[0];
								bonus.itemWindow_deco2.color = decoColor[1];
								bonus.itemWindow.spriteName = "";
								bonus.itemName.text = TextController.GetStringWithId(string.Format("itemName{0}", itemInfo.itemID));
                                bonus.itemRare[itemInfo.rarity - 1].SetActive(true);
								GameObject particle1 = Instantiate(bonus.particle1Prefabs[itemInfo.rarity]) as GameObject;
								GameObject particle2 = Instantiate(bonus.particle2Prefabs[itemInfo.rarity]) as GameObject;
								particle1.transform.parent = bonus.transform;
								particle1.transform.localPosition = Vector3.zero;
								particle1.transform.localScale = Vector3.one;
								particle1.name = "FX_SH_promotion_001";
								particle1.transform.parent = bonus.transform;
								particle1.transform.localPosition = Vector3.zero;
								particle1.transform.localScale = Vector3.one;
								particle1.name = "FX_SH_promotion_loop_001";

								bonus.itemObject.SetActive(true);
								bonus.kinaObject.SetActive(false);
								bonus.bongObject.SetActive(false);
								
								bonusItemInfo = itemInfo;
								break;
							}
						}

						bonus.GetComponent<Animation>().Play();
						SoundController.PlaySound("UI_battle_result_bonus");
					}
					else
					{
						bonus.kinaAmountLabel.text = expansionRewardInfo.value.ToString();
						bonus.itemObject.SetActive(false);
						bonus.kinaObject.SetActive(true);
						bonus.bongObject.SetActive(false);

						bonus.GetComponent<Animation>().Play();
						SoundController.PlaySound("UI_battle_result_bonus");
					}

					yield return new WaitForSeconds(6f);

					GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_03") as GameObject;
					BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
					popup.transform.parent = GameObject.Find("UI Root").transform;
					popup.transform.localScale = Vector3.one;
					popup.transform.localPosition = new Vector3(0f, 130f, 0f);
					popup.legionExpLabel.text = string.Format("+{0}", ExpansionResult.legionExp.ToString());
                    //popup.legionExpLabel2.text = string.Format("+{0}", ExpansionResult.legionExp.ToString());
                    //popup.winPointLabel.text = string.Format("+{0}", ExpansionResult.legionExp.ToString());
					if( UserData.Instance.battleFriendId == 0 )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(false);
						if( expansionRewardInfo.rewardType == 2 )
						{
							popup.bonusItemObeject2.SetActive(true);
							popup.bonusKinaObeject2.SetActive(false);
							popup.bonusBongObeject2.SetActive(false);
                            //popup.bonusItemImage2.spriteName = TextController.GetItemDefine(bonusItemInfo);
                            WeaponAtlasController.SetWeaponSprite(popup.bonusItemImage2, bonusItemInfo);
							popup.bonusItemGlow2.color = Constants.GetItemGlowRareColorValue(bonusItemInfo.rarity);
							popup.bonusItemWindow2.spriteName = Constants.GetItemWindowSpriteName(bonusItemInfo.rarity);
							popup.bonusItemName2.text = TextController.GetStringWithId(string.Format("itemName{0}", bonusItemInfo.itemID));
                            popup.bonusItemRare[bonusItemInfo.rarity - 1].SetActive(true);
						}
						else
						{
							Debug.Log("Kina Amount - " + expansionRewardInfo.value);
							popup.kinaAmountLabel2.text = expansionRewardInfo.value.ToString();
							popup.bonusItemObeject2.SetActive(false);
							popup.bonusKinaObeject2.SetActive(true);
							popup.bonusBongObeject2.SetActive(false);
						}
						popup.GetComponent<Animation>().Play("Battle_Result_Bonus_Sucess EPNF");
					}
					else
					{
						if( UserData.Instance.battleFriendIsMyFriend )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(true);
						}
						else
						{
							popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
							popup.addFriendObject.SetActive(true);
							popup.friendRewardObject.SetActive(false);
						}

						if( expansionRewardInfo.rewardType == 2 )
						{
							popup.bonusItemObeject.SetActive(true);
							popup.bonusKinaObeject.SetActive(false);
							popup.bonusBongObeject.SetActive(false);
                            WeaponAtlasController.SetWeaponSprite(popup.bonusItemImage, bonusItemInfo);
                            //popup.bonusItemImage.spriteName = TextController.GetItemDefine(bonusItemInfo);
							popup.bonusItemGlow.color = Constants.GetItemGlowRareColorValue(bonusItemInfo.rarity);
							popup.bonusItemWindow.spriteName = Constants.GetItemWindowSpriteName(bonusItemInfo.rarity);
							popup.bonusItemName.text = TextController.GetStringWithId(string.Format("itemName{0}", bonusItemInfo.itemID));
                            popup.bonusItemRare[bonusItemInfo.rarity - 1].SetActive(true);
						}
						else
						{
							Debug.Log("Kina Amount - " + expansionRewardInfo.value);
							popup.kinaAmountLabel.text = expansionRewardInfo.value.ToString();
							popup.bonusItemObeject.SetActive(false);
							popup.bonusKinaObeject.SetActive(true);
							popup.bonusBongObeject.SetActive(false);
						}
						popup.GetComponent<Animation>().Play("Battle_Result_Bonus_Sucess EPWF");
					}
				}
				else
				{
					GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_04") as GameObject;
					BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
					popup.transform.parent = GameObject.Find("UI Root").transform;
					popup.transform.localScale = Vector3.one;
					popup.transform.localPosition = new Vector3(0f, 130f, 0f);
					popup.legionExpLabel.text = string.Format("+{0}", ExpansionResult.legionExp.ToString());
                    //popup.legionExpLabel2.text = string.Format("+{0}", ExpansionResult.legionExp.ToString());
                    //popup.winPointLabel.text = string.Format("+{0}", ExpansionResult.legionExp.ToString());
					if( UserData.Instance.battleFriendId == 0 )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(false);
						popup.GetComponent<Animation>().Play("Battle_Result_Bonus_failed EPNF");
					}
					else
					{
						if( UserData.Instance.battleFriendIsMyFriend )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(true);
						}
						else
						{
							popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
							popup.addFriendObject.SetActive(true);
							popup.friendRewardObject.SetActive(false);
						}
						popup.GetComponent<Animation>().Play("Battle_Result_Bonus_failed EPWF");
					}
				}
			}
			else if( WorldSceneManager.isSentSearch )
			{
				if( BattleManager.Instance.isGameWin )
				{
                    Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
					if( UserData.Instance.researchResultData.bonusRewardType != 0 )
					{
                        Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
						GameObject bonusPrefab = ResourceLoader.Load("Prefab/UI/battle_result_bonus") as GameObject;
						BattleResultBonus bonus = (Instantiate(bonusPrefab) as GameObject).GetComponent<BattleResultBonus>();
						bonus.transform.parent = GameObject.Find("UI Root").transform;
						bonus.transform.localScale = Vector3.one;
						bonus.transform.localPosition = Vector3.zero;
						DItem bonusItemInfo = new DItem();
						if( UserData.Instance.researchResultData.bonusRewardType == 3 )
						{
							foreach(DItem itemInfo in GameData.Inst.item)
							{
								if( itemInfo.itemID == result.pratyTrait2 )
								{
									if( itemInfo.rarity == 0 )
									{
										bonus.itemGlow.gameObject.SetActive(false);
									}
                                    //bonus.itemImage.spriteName = TextController.GetItemDefine(itemInfo);
                                    WeaponAtlasController.SetWeaponSprite(bonus.itemImage, itemInfo);
									bonus.itemGlow.color = Constants.GetItemGlowRareColorValue(itemInfo.rarity);
									bonus.itemBg.color = Constants.GetItemBGRareColorValue(itemInfo.rarity);
									Color[] decoColor = Constants.GetItemWindowDecoColorValue(itemInfo.rarity);
									bonus.itemWindow_deco1.color = decoColor[0];
									bonus.itemWindow_deco2.color = decoColor[1];
//									bonus.itemWindow.spriteName = Constants.GetItemWindowSpriteName(itemInfo.rarity);
									bonus.itemName.text = TextController.GetStringWithId(string.Format("itemName{0}", itemInfo.itemID));
                                    bonus.itemRare[itemInfo.rarity - 1].SetActive(true);
									GameObject particle1 = Instantiate(bonus.particle1Prefabs[itemInfo.rarity]) as GameObject;
									GameObject particle2 = Instantiate(bonus.particle2Prefabs[itemInfo.rarity]) as GameObject;
									particle1.transform.parent = bonus.transform;
									particle1.transform.localPosition = Vector3.zero;
									particle1.transform.localScale = Vector3.one;
									particle1.name = "FX_SH_promotion_001";
									particle1.transform.parent = bonus.transform;
									particle1.transform.localPosition = Vector3.zero;
									particle1.transform.localScale = Vector3.one;
									particle1.name = "FX_SH_promotion_loop_001";

									bonus.itemObject.SetActive(true);
									bonus.kinaObject.SetActive(false);
									bonus.bongObject.SetActive(false);
									
									bonusItemInfo = itemInfo;
									break;
								}
							}

							bonus.GetComponent<Animation>().Play();
							SoundController.PlaySound("UI_battle_result_bonus");
						}
						else if( UserData.Instance.researchResultData.bonusRewardType == 2 )
						{
							bonus.bongAmountLabel.text = UserData.Instance.researchResultData.pratyTrait2.ToString();
							bonus.itemObject.SetActive(false);
							bonus.kinaObject.SetActive(false);
							bonus.bongObject.SetActive(true);

							bonus.GetComponent<Animation>().Play();
							SoundController.PlaySound("UI_battle_result_bonus");
						}
						else if( UserData.Instance.researchResultData.bonusRewardType == 1 )
						{
							bonus.kinaAmountLabel.text = UserData.Instance.researchResultData.pratyTrait2.ToString();
							bonus.itemObject.SetActive(false);
							bonus.kinaObject.SetActive(true);
							bonus.bongObject.SetActive(false);

							bonus.GetComponent<Animation>().Play();
							SoundController.PlaySound("UI_battle_result_bonus");
						}
                        Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
						yield return new WaitForSeconds(6f);
                        Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
						GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_00") as GameObject;
						BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
						popup.transform.parent = GameObject.Find("UI Root").transform;
						popup.transform.localScale = Vector3.one;
						popup.transform.localPosition = new Vector3(0f, 130f, 0f);
						popup.legionExpLabel.text = string.Format("+{0}", UserData.Instance.researchResultData.legionExp.ToString());
						popup.regionExpLabel.text = string.Format("+{0}", UserData.Instance.researchResultData.regionExp.ToString());
						popup.regionNameLabel.text = TextController.GetStringWithId(string.Format("region{0}", UserData.Instance.researchResultData.regionId));
                        Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
						if( UserData.Instance.researchResultData.bonusRewardType == 3 )
						{
                            //popup.bonusItemImage.spriteName = TextController.GetItemDefine(bonusItemInfo);
                            WeaponAtlasController.SetWeaponSprite(popup.bonusItemImage, bonusItemInfo);
							popup.bonusItemGlow.color = Constants.GetItemGlowRareColorValue(bonusItemInfo.rarity);
							popup.bonusItemWindow.spriteName = Constants.GetItemWindowSpriteName(bonusItemInfo.rarity);
							popup.bonusItemName.text = TextController.GetStringWithId(string.Format("itemName{0}", bonusItemInfo.itemID));
                            popup.bonusItemRare[bonusItemInfo.rarity - 1].SetActive(true);
							popup.bonusKinaObeject.SetActive(false);
							popup.bonusItemObeject.SetActive(true);
							popup.bonusBongObeject.SetActive(false);
						}
						else if( UserData.Instance.researchResultData.bonusRewardType == 1 )
                        {
                            Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
							popup.kinaAmountLabel.text = UserData.Instance.researchResultData.pratyTrait2.ToString();
							popup.bonusKinaObeject.SetActive(true);
							popup.bonusItemObeject.SetActive(false);
							popup.bonusBongObeject.SetActive(false);
						}
						else if( UserData.Instance.researchResultData.bonusRewardType == 2 )
						{
							popup.bongAmountLabel.text = UserData.Instance.researchResultData.pratyTrait2.ToString();
							popup.bonusBongObeject.SetActive(true);
							popup.bonusItemObeject.SetActive(false);
							popup.bonusKinaObeject.SetActive(false);
						}
                        Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
						if( UserData.Instance.battleFriendId == 0 )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(false);
						}
						else
						{
							if( UserData.Instance.battleFriendIsMyFriend )
							{
								popup.addFriendObject.SetActive(false);
								popup.friendRewardObject.SetActive(true);
							}
							else
							{
								popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
								popup.addFriendObject.SetActive(true);
								popup.friendRewardObject.SetActive(false);
							}
						}
                        Debug.LogWarning("UserData.Instance.battleFriendId - " + UserData.Instance.battleFriendId);
					}
					else
					{
						GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_01") as GameObject;
						BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
						popup.transform.parent = GameObject.Find("UI Root").transform;
						popup.transform.localScale = Vector3.one;
						popup.transform.localPosition = new Vector3(0f, 130f, 0f);
						popup.legionExpLabel.text = string.Format("+{0}", UserData.Instance.researchResultData.legionExp.ToString());
						popup.regionExpLabel.text = string.Format("+{0}", UserData.Instance.researchResultData.regionExp.ToString());
						popup.regionNameLabel.text = TextController.GetStringWithId(string.Format("region{0}", UserData.Instance.researchResultData.regionId));
						if( UserData.Instance.battleFriendId == 0 )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(false);
						}
						else
						{
							if( UserData.Instance.battleFriendIsMyFriend )
							{
								popup.addFriendObject.SetActive(false);
								popup.friendRewardObject.SetActive(true);
							}
							else
							{
								popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
								popup.addFriendObject.SetActive(true);
								popup.friendRewardObject.SetActive(false);
							}
						}
					}
				}
				else
				{
					GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_02") as GameObject;
					BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
					popup.transform.parent = GameObject.Find("UI Root").transform;
					popup.transform.localScale = Vector3.one;
					popup.transform.localPosition = new Vector3(0f, 130f, 0f);
					popup.legionExpLabel.text = string.Format("+{0}", UserData.Instance.researchResultData.legionExp.ToString());
					popup.regionExpLabel.text = string.Format("+{0}", UserData.Instance.researchResultData.regionExp.ToString());
					popup.regionNameLabel.text = TextController.GetStringWithId(string.Format("region{0}", UserData.Instance.researchResultData.regionId));
					if( UserData.Instance.battleFriendId == 0 )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(false);
					}
					else
					{
						if( UserData.Instance.battleFriendIsMyFriend )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(true);
						}
						else
						{
							popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
							popup.addFriendObject.SetActive(true);
							popup.friendRewardObject.SetActive(false);
						}
					}
				}
			}
			else if( UserData.Instance.isQuickPVPBattle )
			{
				PvpEndResult quickPvPResult = UserData.Instance.quickPvPResultData;
				Debug.Log(quickPvPResult.rewardType);
				if( BattleManager.Instance.isGameWin )
				{
					DItem bonusItemInfo = new DItem();
					if( quickPvPResult.rewardType == 4 )
					{
						GameObject bonusPrefab = ResourceLoader.Load("Prefab/UI/battle_result_bonus") as GameObject;
						BattleResultBonus bonus = (Instantiate(bonusPrefab) as GameObject).GetComponent<BattleResultBonus>();
						bonus.transform.parent = GameObject.Find("UI Root").transform;
						bonus.transform.localScale = Vector3.one;
						bonus.transform.localPosition = Vector3.zero;
						foreach(DItem itemInfo in GameData.Inst.item)
						{
							if( itemInfo.itemID == quickPvPResult.itemId )
							{
								if( itemInfo.rarity == 0 )
								{
									bonus.itemGlow.gameObject.SetActive(false);
								}
                                //bonus.itemImage.spriteName = TextController.GetItemDefine(itemInfo);
                                WeaponAtlasController.SetWeaponSprite(bonus.itemImage, itemInfo);
								bonus.itemGlow.color = Constants.GetItemGlowRareColorValue(itemInfo.rarity);
								bonus.itemBg.color = Constants.GetItemBGRareColorValue(itemInfo.rarity);
								Color[] decoColor = Constants.GetItemWindowDecoColorValue(itemInfo.rarity);
								bonus.itemWindow_deco1.color = decoColor[0];
								bonus.itemWindow_deco2.color = decoColor[1];
//								bonus.itemWindow.spriteName = "";
								bonus.itemName.text = TextController.GetStringWithId(string.Format("itemName{0}", itemInfo.itemID));
                                bonus.itemRare[itemInfo.rarity - 1].SetActive(true);
								GameObject particle1 = Instantiate(bonus.particle1Prefabs[itemInfo.rarity]) as GameObject;
								GameObject particle2 = Instantiate(bonus.particle2Prefabs[itemInfo.rarity]) as GameObject;
								particle1.transform.parent = bonus.transform;
								particle1.transform.localPosition = Vector3.zero;
								particle1.transform.localScale = Vector3.one;
								particle1.name = "FX_SH_promotion_001";
								particle1.transform.parent = bonus.transform;
								particle1.transform.localPosition = Vector3.zero;
								particle1.transform.localScale = Vector3.one;
								particle1.name = "FX_SH_promotion_loop_001";
								
								bonus.itemObject.SetActive(true);
								bonus.kinaObject.SetActive(false);
								bonus.bongObject.SetActive(false);
								
								bonusItemInfo = itemInfo;
								break;
							}
						}

						bonus.GetComponent<Animation>().Play();
						SoundController.PlaySound("UI_battle_result_bonus");
					}
					else if( quickPvPResult.rewardType == 1 )
					{
						GameObject bonusPrefab = ResourceLoader.Load("Prefab/UI/battle_result_bonus") as GameObject;
						BattleResultBonus bonus = (Instantiate(bonusPrefab) as GameObject).GetComponent<BattleResultBonus>();
						bonus.transform.parent = GameObject.Find("UI Root").transform;
						bonus.transform.localScale = Vector3.one;
						bonus.transform.localPosition = Vector3.zero;
						bonus.kinaAmountLabel.text = quickPvPResult.amount.ToString();
						bonus.itemObject.SetActive(false);
						bonus.kinaObject.SetActive(true);
						bonus.bongObject.SetActive(false);

						bonus.GetComponent<Animation>().Play();
						SoundController.PlaySound("UI_battle_result_bonus");
					}
					else if( quickPvPResult.rewardType == 2 )
					{
//						GameObject bonusPrefab = ResourcesManager.Load("Prefab/UI/battle_result_bonus") as GameObject;
//						BattleResultBonus bonus = (Instantiate(bonusPrefab) as GameObject).GetComponent<BattleResultBonus>();
//						bonus.transform.parent = GameObject.Find("UI Root").transform;
//						bonus.transform.localScale = Vector3.one;
//						bonus.transform.localPosition = Vector3.zero;
//						bonus.kinaAmountLabel.text = quickPvPResult.amount.ToString();
//						bonus.itemObject.SetActive(false);
//						bonus.kinaObject.SetActive(false);
//						bonus.bongObject.SetActive(false);

//						bonus.GetComponent<Animation>().Play();
					}
					else if( quickPvPResult.rewardType == 3 )
					{
						GameObject bonusPrefab = ResourceLoader.Load("Prefab/UI/battle_result_bonus") as GameObject;
						BattleResultBonus bonus = (Instantiate(bonusPrefab) as GameObject).GetComponent<BattleResultBonus>();
						bonus.transform.parent = GameObject.Find("UI Root").transform;
						bonus.transform.localScale = Vector3.one;
						bonus.transform.localPosition = Vector3.zero;
						bonus.bongAmountLabel.text = quickPvPResult.amount.ToString();
						bonus.itemObject.SetActive(false);
						bonus.kinaObject.SetActive(false);
						bonus.bongObject.SetActive(true);

						bonus.GetComponent<Animation>().Play();
						SoundController.PlaySound("UI_battle_result_bonus");
					}

					if( quickPvPResult.rewardType != 0 )
						yield return new WaitForSeconds(6f);
					
					GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_03") as GameObject;
					BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
					popup.transform.parent = GameObject.Find("UI Root").transform;
					popup.transform.localScale = Vector3.one;
					popup.transform.localPosition = new Vector3(0f, 130f, 0f);
					popup.legionExpLabel.text = string.Format("+{0}", quickPvPResult.legionExp.ToString());
                    //popup.legionExpLabel2.text = string.Format("+{0}", quickPvPResult.legionExp.ToString());
                    popup.winPointLabel.text = string.Format("+{0}", quickPvPResult.winPoint.ToString());
                    popup.winPointLabelObject.SetActive(true);
					if( UserData.Instance.battleFriendId == 0 )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(false);
						if( quickPvPResult.rewardType == 4 )
						{
							popup.bonusItemObeject2.SetActive(true);
							popup.bonusKinaObeject2.SetActive(false);
							popup.bonusBongObeject2.SetActive(false);
                            //popup.bonusItemImage2.spriteName = TextController.GetItemDefine(bonusItemInfo);
                            WeaponAtlasController.SetWeaponSprite(popup.bonusItemImage2, bonusItemInfo);
							popup.bonusItemGlow2.color = Constants.GetItemGlowRareColorValue(bonusItemInfo.rarity);
							popup.bonusItemWindow2.spriteName = Constants.GetItemWindowSpriteName(bonusItemInfo.rarity);
							popup.bonusItemName2.text = TextController.GetStringWithId(string.Format("itemName{0}", bonusItemInfo.itemID));
                            popup.bonusItemRare[bonusItemInfo.rarity - 1].SetActive(true);
						}
						else if( quickPvPResult.rewardType == 1 )
						{
							popup.kinaAmountLabel2.text = quickPvPResult.amount.ToString();
							popup.bonusItemObeject2.SetActive(false);
							popup.bonusKinaObeject2.SetActive(true);
							popup.bonusBongObeject2.SetActive(false);
						}
						else if( quickPvPResult.rewardType == 2 )
						{
//							popup.kinaAmountLabel2.text = quickPvPResult.amount.ToString();
//							popup.bonusItemObeject2.SetActive(false);
//							popup.bonusKinaObeject2.SetActive(false);
//							popup.bonusBongObeject2.SetActive(false);
						}
						else if( quickPvPResult.rewardType == 3 )
						{
							popup.bongAmountLabel2.text = quickPvPResult.amount.ToString();
							popup.bonusItemObeject2.SetActive(false);
							popup.bonusKinaObeject2.SetActive(false);
							popup.bonusBongObeject2.SetActive(true);
						}
						if( quickPvPResult.rewardType != 0 )
							popup.GetComponent<Animation>().Play("Battle_Result_Bonus_Sucess EPNF");
						else 
						{
							popup.bonusItemTextObject2.SetActive(false);
							popup.noBonusItemObject2.SetActive(true);
							popup.GetComponent<Animation>().Play("Battle_Result_Bonus_Sucess EPNF_NT");
						}
					}
					else
					{
						if( UserData.Instance.battleFriendIsMyFriend )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(true);
						}
						else
						{
							popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
							popup.addFriendObject.SetActive(true);
							popup.friendRewardObject.SetActive(false);
						}
						
						if( quickPvPResult.rewardType == 2 )
						{
							popup.bonusItemObeject.SetActive(true);
							popup.bonusKinaObeject.SetActive(false);
							popup.bonusBongObeject.SetActive(false);
							
                            //popup.bonusItemImage.spriteName = TextController.GetItemDefine(bonusItemInfo);
                            WeaponAtlasController.SetWeaponSprite(popup.bonusItemImage, bonusItemInfo);
							popup.bonusItemGlow.color = Constants.GetItemGlowRareColorValue(bonusItemInfo.rarity);
							popup.bonusItemWindow.spriteName = Constants.GetItemWindowSpriteName(bonusItemInfo.rarity);
							popup.bonusItemName.text = TextController.GetStringWithId(string.Format("itemName{0}", bonusItemInfo.itemID));
                            popup.bonusItemRare[bonusItemInfo.rarity - 1].SetActive(true);
						}
						else if( quickPvPResult.rewardType == 1 )
						{
							popup.bonusKinaObeject2.transform.FindChild("item_01").GetComponent<UISprite>().spriteName = "item_quina";
							popup.kinaAmountLabel.text = quickPvPResult.amount.ToString();
							popup.bonusItemObeject2.SetActive(false);
							popup.bonusKinaObeject2.SetActive(true);
							popup.bonusBongObeject2.SetActive(false);
						}
						else if( quickPvPResult.rewardType == 2 )
						{
							popup.bonusKinaObeject2.transform.FindChild("item_01").GetComponent<UISprite>().spriteName = "item_jam";
							popup.kinaAmountLabel2.text = quickPvPResult.amount.ToString();
							popup.bonusItemObeject2.SetActive(false);
							popup.bonusKinaObeject2.SetActive(true);
							popup.bonusBongObeject2.SetActive(false);
						}
						else if( quickPvPResult.rewardType == 3 )
						{
							popup.bongAmountLabel.text = quickPvPResult.amount.ToString();
							popup.bonusItemObeject2.SetActive(false);
							popup.bonusKinaObeject2.SetActive(false);
							popup.bonusBongObeject2.SetActive(true);
						}

						if( quickPvPResult.rewardType != 0 )
							popup.GetComponent<Animation>().Play("Battle_Result_Bonus_Sucess EPWF");
						else
						{
							popup.bonusItemTextObject2.SetActive(false);
							popup.noBonusItemObject2.SetActive(true);
							popup.GetComponent<Animation>().Play("Battle_Result_Bonus_Sucess EPWF_NT");
						}
					}
				}
				else
				{
					GameObject popupPrefab = ResourceLoader.Load("Prefab/UI/battle_result_popup_04") as GameObject;
					BattleResultPopup popup = (Instantiate(popupPrefab) as GameObject).GetComponent<BattleResultPopup>();
					popup.transform.parent = GameObject.Find("UI Root").transform;
					popup.transform.localScale = Vector3.one;
					popup.transform.localPosition = new Vector3(0f, 130f, 0f);
					popup.legionExpLabel.text = string.Format("+{0}", quickPvPResult.legionExp.ToString());
                    //popup.legionExpLabel2.text = string.Format("+{0}", quickPvPResult.legionExp.ToString());
                    popup.winPointLabel.text = string.Format("+{0}", quickPvPResult.winPoint.ToString());
                    popup.winPointLabelObject.SetActive(true);
					if( UserData.Instance.battleFriendId == 0 )
					{
						popup.addFriendObject.SetActive(false);
						popup.friendRewardObject.SetActive(false);
						popup.GetComponent<Animation>().Play("Battle_Result_Bonus_failed EPNF");
					}
					else
					{
						if( UserData.Instance.battleFriendIsMyFriend )
						{
							popup.addFriendObject.SetActive(false);
							popup.friendRewardObject.SetActive(true);
						}
						else
						{
							popup.addFriendLabel.text = TextController.GetStringWithId("uiPopupFriendCaution1").Replace("{0}", UserData.Instance.battleFriend.lv.ToString()).Replace("{1}", UserData.Instance.battleFriend.name);
							popup.addFriendObject.SetActive(true);
							popup.friendRewardObject.SetActive(false);
						}
						popup.GetComponent<Animation>().Play("Battle_Result_Bonus_failed EPWF");
					}
				}
			}
			ToastUtility.LevelUpToast();
            QuestManager.instance.ShowQuestCompleteToast();
		}
	}

	public ExpHUDText[] playerExpHUDImage;
	public void ShowGuardHUDImage(bool isPlayer, int index)
	{
		Debug.Log("ShowGuardHUDImage");
		if( isPlayer )
		{
			if( playerExpHUDImage[index-1].GetComponent<UIFollowTarget>() == null )
				playerExpHUDImage[index-1].gameObject.AddComponent<UIFollowTarget>().target = BattleManager.Instance.playerList[index-1].pawnManifest.hudHeadTrans;
			else
				playerExpHUDImage[index-1].gameObject.GetComponent<UIFollowTarget>().target = BattleManager.Instance.playerList[index-1].pawnManifest.hudHeadTrans;
		}
		else
		{
			if( playerExpHUDImage[index-1].GetComponent<UIFollowTarget>() == null )
				playerExpHUDImage[index-1].gameObject.AddComponent<UIFollowTarget>().target = BattleManager.Instance.enemyList[index-1].pawnManifest.hudHeadTrans;
			else
				playerExpHUDImage[index-1].gameObject.GetComponent<UIFollowTarget>().target = BattleManager.Instance.enemyList[index-1].pawnManifest.hudHeadTrans;
		}
		playerExpHUDImage[index-1].ShowGuardImage();
	}

	public void HideBattleUI()
	{
		foreach(Animation ani in myMemberStatusBarAni)
		{
			ani.Stop();
		}

		foreach(Animation ani in enermyMemberStatusBarAni)
		{
			ani.Stop();
		}

		battleUIObject.SetActive(false);
	}

	public void ShowSuperGageBrokenOutAnimation()
	{
//		for(int i=0; i<superGageAnimations.Length; i++)
//		{
//			if(superGageAnimations[i]==null) {
//				Debug.LogError("superGage null");
//				break;
//			}
//			superGageAnimations[i].Play("Ulti_0"+(i+1)+"_Break Out");
//		}
		superGagePhase = 0;
		SetSuperGage(0);
		overDriveTextBySuperGage.GetComponent<Animation>().Play("Bar_Over Drive OFF");
		superGageOverDriveOnObject.SetActive(false);
		superGageObjects[0].transform.parent.parent.gameObject.GetComponent<Animation>().Stop();

		superSkillCrystalObject[2].GetComponent<Animation>().Play("Take 001");
		crystalBrokenEffect.SetActive(true);
		ParticleSystem ps = crystalBrokenEffect.GetComponentInChildren<ParticleSystem>();
		if(ps==null)
			Debug.LogError("  Particle null   ShowSuperGageBrokenOutAnimation");
		else
			ps.Play();
	}

	public void ShowOverDriveStartTextEffect()
	{
		totalComboCount = 1;
		overDriveTime = BattleSetting.Instance.overdriveModeTime/BattleSetting.Instance.overdriveModeTimeScale;
		HideBattleUI();
		overDriveStartTextObject.SetActive(true);
		overDriveStartTextObject.GetComponent<Animation>().Play("Overdrive");
		SoundController.PlaySound("UI_over drive");

		Invoke("ShowOverDriveTimer", 2f);
	}

	public void ShowOverDriveTimer()
	{
		overDriveTimerNumberLabel.text = ((int)overDriveTime).ToString();
		overDriveTimerObject.SetActive(true);
	}

	public void HideOverDriveTimer()
	{
		HideComboEffect();
		overDriveTimerObject.SetActive(false);
		overDriveTime = BattleSetting.Instance.overdriveModeTime;

		crystalBrokenEffect.SetActive(false);
		superSkillCrystalObject[2].GetComponent<Animation>().Play("Take 002");
		battleUIObject.SetActive(true);
		comboEffectObject.SetActive(false);
	}

	int totalComboCount = 1;
	public void SetComboCount()
	{
		if( !comboEffectObject.activeSelf )
		{
			comboEffectObject.SetActive(true);
			comboCountLabel.text = string.Format("{0:00}", totalComboCount++);
			comboEffectObject.GetComponent<Animation>().Play("battle_sup attack_combo on");
			SoundController.PlaySound("UI_support_attack_combo");
		}
		else
		{
			comboCountLabel.text = string.Format("{0:00}", totalComboCount++);
			comboEffectObject.GetComponent<Animation>().Play("battle_sup attack_combo push");
			SoundController.PlaySound("UI_support_attack_combo");
		}
	}

	public void HideComboEffect()
	{
		comboEffectObject.GetComponent<Animation>().Play("battle_sup attack_combo off");
	}

	public float ShowBattleResultTextEffect()
	{
		if( BattleManager.Instance.isGameWin )
		{
			battleWinTextEffect.SetActive(true);
			SoundController.PlaySound("UI_Result_Text_Win");
		}
		else
		{
			battleLoseTextEffect.SetActive(true);
			SoundController.PlaySound("UI_Result_Text_Fail");
		}

		return 2f;
	}

	public bool isClickedSpeedButton = false;
	public void OnClickedSpeedUpButton()
	{
		Debug.Log("OnClickedSpeedUpButton");
        //speedUpButtonObject.SetActive(true);
        //speedUpButtonObject.GetComponent<Animation>().Play("battle_bust speed");
		isClickedSpeedButton = true;
	}

	public void OnClickedFriendAttackButton()
	{
		Debug.Log("OnClickedFriendAttackButton");
		//BattleManager.Instance.ActionFriendPawn();
		friendAttackButtonObject.GetComponent<EPButton>().isEnabled = false;
	}

	public void OnPressedSkillButton()
	{
//		for(int i=0; i<superGageAnimations.Length; i++)
//		{
//			superGageAnimations[i].Play("Ulti_0"+(i+1)+"_Push");
//		}
	}

	public void OnClickedCheatGaugeFull()
	{
		Debug.Log("OnClickedCheatGaugeFull");
		BattleManager.Instance.IncreaseRage(0,0,100);
	}

	public void OnClickedSkillButton()
	{
		Debug.Log("OnClickedSkillButton");
		if(!BattleManager.Instance.CanUseRageSkill())
			return;

		if(BattleManager.Instance.rageValue>=50)
		{
			//if(BattleManager.Instance.rageValue<100) {//overdrive모드인경우는 바로 BreakOut되므로 필살기의 경우만 idle보여주도록
//				for(int i=0; i<superGageAnimations.Length; i++)
//				{
//					if(superGageAnimations[i]==null) {
//						Debug.LogError("superGage null");
//						break;
//					}
//					superGageAnimations[i].Play("Ulti_0"+(i+1)+"_Push idle");
//				}
			//}
			BattleManager.Instance.UseRageSkill();
		}
	}
}
